import { FetchResult, Observable } from "@apollo/client";
import { NetworkError } from "@apollo/client/errors";
// import { showMessage } from 'react-native-flash-message';

import { ErrorMatchHandler } from "./error-handler";
export interface NetworkErrorMatchHandler extends ErrorMatchHandler {
  match(error: NetworkError): boolean;

  handle(error: NetworkError): Observable<FetchResult> | void;
}

export class DefaultNetworkErrorHandler implements NetworkErrorMatchHandler {
  match(error: NetworkError): boolean {
    // @ts-ignore
    return error !== undefined;
  }

  // eslint-disable n/handle-callback-err
  handle(
    error: NetworkError
  ): void | Observable<
    FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>
  > {
    console.log(error);
    console.log({
      position: "bottom",
      statusBarHeight: 20,
      message: "网络错误",
      type: "danger",
      duration: 3000,
    });
  }
}
